package yzx.firstletter.appList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class LetterSelectItemView extends TextView{

    public LetterSelectItemView(Context context) {
        this(context, null);
    }
    public LetterSelectItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public LetterSelectItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init(){
        post(new Runnable() {
            public void run() {
                setText(getTag().toString());
            }
        });
    }



    private int selectedBgColor = Color.WHITE;
    private boolean isSelected;

    /** 设置选中/非选中状态 */
    public void setSelectedState(boolean selected){
        this.isSelected = selected;
        invalidate();
    }
    /** 选中的背景颜色 */
    public void setSelectedBgColor(int selectedBgColor) {
        this.selectedBgColor = selectedBgColor;
        paint.setColor(this.selectedBgColor);
        invalidate();
    }

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    {
        paint.setColor(selectedBgColor);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        if(isSelected)
            canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
        super.onDraw(canvas);
    }

}
